import { Controller } from "../../mvc/core/Controller";
import { IView } from "../../mvc/interfaces/IView";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { SRomanic } from "../../../Message/Game/SRomanic";
import { SAttribute } from "../../../Message/Public/SAttribute";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { DataEvent } from "../events/DataEvent";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { RomanicView } from "../view/romanic/RomanicView";
import { GameLayout } from "../GameLayout";
import { MagpieBridgeView } from "../view/romanic/MagpieBridgeView";
import { CellHappyView } from "../view/romanic/CellHappyView";
import { Language } from "../../../extend/language/Language";
import { CakeMakeView } from "../view/romanic/CakeMakeView";
//class RomanicController
    
    export  class RomanicController extends Controller
    {
       

        protected /* override */ initView(): IView
        {
            return null;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.RomanicDataCommand, this.onRomanicDataHandler);
            NetDispatcher.addCmdListener(ServerCommand.RomanicEndCommand, this.onRomanicEndHandler);
            NetDispatcher.addCmdListener(ServerCommand.CellHappyDataCommand, this.onCellHappyDataHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicMakeCakeUpdate, this.onCakeMakeDataHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.onSceneUpdate);
            return;
        }

        public onRomanicDataHandler(arg1: SRomanic): void
        {
            if (cache.role.entityInfo.level >= 35) 
            {
                if (this._isMagpieBridge) 
                {
                    this.magpieBridgeView.show();
                    this.magpieBridgeView.updateCellHappy(arg1.value, arg1.maxValue);
                }
                else 
                {
                    this.romanicView.show();
                    this.romanicView.updateRomanic(arg1.value, arg1.maxValue);
                }
            }
            return;
        }

        public onRomanicEndHandler(arg1: Object): void
        {
            if (this._romanicView) 
            {
                this.romanicView.hide();
            }
            if (this._magpieBridgeView) 
            {
                this.magpieBridgeView.hide();
            }
            return;
        }

        public onCellHappyDataHandler(arg1: SAttribute): void
        {
            this.cellHappyView.show();
            this.cellHappyView.updateCellHappy(arg1.value, int(arg1.valueStr));
            return;
        }

        public onCakeMakeDataHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SAttribute;
            this.cakeMakeView.show();
            this.cakeMakeView.updateCellHappy(loc1.value, int(loc1.valueStr));
            return;
        }

        public onSceneUpdate(arg1: DataEvent): void
        {
            if (GameMapUtil.curMapState.isCrossMainCity) 
            {
                this._isInCrossSkyCityMap = true;
            }
            else if (this._isInCrossSkyCityMap) 
            {
                this._isInCrossSkyCityMap = false;
                this.cellHappyView.hide();
            }
            return;
        }

        public get romanicView(): RomanicView
        {
            if (!this._romanicView) 
            {
                this._romanicView = new RomanicView();
                GameLayout.instance.resize();
            }
            return this._romanicView;
        }

        public get magpieBridgeView(): MagpieBridgeView
        {
            if (!this._magpieBridgeView) 
            {
                this._magpieBridgeView = new MagpieBridgeView();
                GameLayout.instance.resize();
            }
            return this._magpieBridgeView;
        }

        public get cellHappyView(): CellHappyView
        {
            if (!this._cellHappyView) 
            {
                this._cellHappyView = new CellHappyView();
                this._cellHappyView.desText = Language.getString(44003);
                GameLayout.instance.resize();
            }
            return this._cellHappyView;
        }

        public get cakeMakeView(): CakeMakeView
        {
            if (!this._cakeMakeView) 
            {
                this._cakeMakeView = new CakeMakeView();
                this._cakeMakeView.desText = Language.getString(44004);
                GameLayout.instance.resize();
            }
            return this._cakeMakeView;
        }

        public isHaveRomanicView(): Boolean
        {
            return !(this._romanicView == null);
        }

        public isHaveCellHappyView(): Boolean
        {
            return !(this._cellHappyView == null);
        }

        public isHaveCakeMakeView(): Boolean
        {
            return !(this._cakeMakeView == null);
        }

        public isHaveMagpieBridgeView(): Boolean
        {
            return !(this._magpieBridgeView == null);
        }

        public /* var */_isMagpieBridge: Boolean=true;

        private /* var */_isInCrossSkyCityMap: Boolean=false;

        private /* var */_romanicView: RomanicView;

        private /* var */_magpieBridgeView: MagpieBridgeView;

        private /* var */_cellHappyView: CellHappyView;

        private /* var */_cakeMakeView: CakeMakeView;
    }
